package com.cskaoyan.utils;


import com.mchange.v2.c3p0.ComboPooledDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * 创建日期: 2022/10/11 10:16
 *
 * @author ciggar
 */
public class C3p0Utils {

    static DataSource dataSource;


    static {

        // new 出来之后会自动去加载c3p0-config.xml配置文件中的内容
        dataSource = new ComboPooledDataSource();



        // 也可以手动加载
        //comboPooledDataSource.setJdbcUrl();
        //comboPooledDataSource.setUser();
        //comboPooledDataSource.setPassword();
        //comboPooledDataSource.setDriverClass();

    }


    // 获取连接的方法
    public static Connection getConnection(){

        Connection connection = null;
        try {
            connection = dataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return connection;


    }
}
